﻿#region

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;
using BusinessObjects;

#endregion

namespace FastTrackCabService.AdminPanel
{
    public partial class CustomerFullView : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            int cusId;
            if (int.TryParse(Request.QueryString["cusId"], out cusId))
            {
                var customer = new Customer
                {
                    CustomerId = cusId
                };

                CustomerBLL.GetCustomerType(customer);

                switch (customer.Type)
                {
                    case "Personal":
                        var personalCustomer = new PersonalCustomer
                        {
                            CustomerId = cusId
                        };

                        PersonalCustomerBLL.GetPersonalCustomerDetails(personalCustomer);

                        DetailsView1.Visible = true;
                        DetailsView1.DataSource = new List<PersonalCustomer> {personalCustomer};
                        DetailsView1.DataBind();
                        break;

                    case "Business":
                        var businessCustomer = new BusinessCustomer
                        {
                            CustomerId = cusId
                        };

                        BusinessCustomerBLL.GetBusinessCustomerDetails(businessCustomer);

                        DetailsView2.Visible = true;
                        DetailsView2.DataSource = new List<BusinessCustomer> {businessCustomer};
                        DetailsView2.DataBind();
                        break;
                }
            }
            else
            {
                Response.Redirect("Customers.aspx");
            }
        }

        protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
        {
            Response.Redirect("EditCustomerForm.aspx?cusId=" + Request.QueryString["cusId"]);
        }
    }
}